home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Blitting Class Library / Secure Macintosh Ports / SecureCGrafPort.cp next >
Encoding:
Text File  |  1995-10-20  |  1.6 KB  |  79 lines  |  [TEXT/CWIE]

  1. // SecureCGrafPort.cp, the SecureCGrafPort class, useful for generating onscreen
  2. //    CGrafPorts for those who do not use a framework to make CGrafPorts for them.
  3.  
  4. // copyright © 1995, Macneil Shonle. All rights reserved.
  5.  
  6. #ifndef __SECURECGRAFPORT__
  7. #include <SecureCGrafPort.h>
  8. #endif
  9.  
  10. #ifndef __GWORLDSETTER__
  11. #include <GWorldSetter.h>
  12. #endif
  13.  
  14. // constructs the CGrafPort to have drawings visible in the bounds argument
  15. //    may throw: xalloc, invalidargument
  16. SecureCGrafPort::SecureCGrafPort(const Rect& bounds) throw(xalloc, invalidargument)
  17.     : port(new CGrafPort)
  18. {
  19.     if (port == 0)
  20.         throw xalloc("new port failed", "SecureCGrafPtr::SecureCGrafPtr");
  21.     ::OpenCPort(port);
  22.     
  23.     GWorldSetter setTo(port);
  24.     
  25.     Rect zeroBounds = bounds;
  26.     ::OffsetRect(&zeroBounds, -zeroBounds.left, -zeroBounds.top);
  27.     
  28.     RgnHandle drawRegion = ::NewRgn();
  29.     ::OpenRgn();
  30.     ::FrameRect(&zeroBounds);
  31.     ::CloseRgn(drawRegion);
  32.     
  33.     ::CopyRgn(drawRegion, port->visRgn);
  34.     ::CopyRgn(drawRegion, port->clipRgn);
  35.     
  36.     ::PortSize(zeroBounds.right, zeroBounds.bottom);
  37.     ::MovePortTo(bounds.left, bounds.top);
  38. }
  39.  
  40. SecureCGrafPort::~SecureCGrafPort()
  41. {
  42.     ::CloseCPort(port);
  43.     delete port;
  44. }
  45.  
  46. Rect& SecureCGrafPort::portRect() const
  47. {
  48.     return port->portRect;
  49. }
  50.  
  51. BitMapPtr SecureCGrafPort::bitMap() const
  52. {
  53.     return &GrafPtr(port)->portBits;
  54. }
  55.  
  56. short SecureCGrafPort::width() const
  57. {
  58.     return port->portRect.right - port->portRect.left;
  59. }
  60.  
  61. short SecureCGrafPort::height() const
  62. {
  63.     return port->portRect.bottom - port->portRect.top;
  64. }
  65.  
  66. CGrafPtr SecureCGrafPort::getMacPort() const
  67. {
  68.     return port;
  69. }
  70.  
  71. GDHandle SecureCGrafPort::getMacGD() const
  72. {
  73.     return ::GetMainDevice();
  74. }
  75.  
  76. SecureCGrafPort::operator CGrafPtr() const
  77. {
  78.     return port;
  79. }